package crm.view.Custom;

import crm.dao.impl.FeedbackInfoSqlSeverImpl;
import crm.entity.FeedbackInfo;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class commitFeedBack implements ActionListener {
    JFrame frame = null;

    JLabel name = null;
    JLabel fedTime = null;
    JLabel fedPId = null;
    JLabel fedInfo = null;
    JLabel solved = null;



    JTextField NameField = null;
    JTextField fedTimeField = null;
    JTextField fedPIdField = null;
    JTextField fedInfoField = null;
    JTextField solvedField = null;



    
    JButton btn = null;
    JButton btn2 = null;

    public static void main(String[] args) {
        new commitFeedBack();
    }

    public commitFeedBack() {
        init();
        frame.setBounds(680, 200, 600, 500);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setLayout(null);
        frame.setVisible(true);
    }

    public void init() {
        frame = new JFrame("提交反馈");
        name = new JLabel("输入您的姓名:");
        fedTime = new JLabel("反馈时间:");
        fedPId = new JLabel("反馈产品编号:");
        fedInfo = new JLabel("反馈内容:");
        solved = new JLabel("是否解决:");

        NameField = new JTextField();
        fedTimeField = new JTextField();
        fedPIdField = new JTextField();
        fedInfoField = new JTextField();
        solvedField = new JTextField();
        solvedField = new JTextField();
        btn = new JButton("提交");
        btn2 = new JButton("清空");
        Font font = new Font("楷体", 2, 20);
        btn.setFont(font);
        btn2.setFont(font);
        name.setFont(font);
        NameField.setFont(font);
        fedTime.setFont(font);
        fedTimeField.setFont(font);
        fedPId.setFont(font);
        fedPIdField.setFont(font);
        fedInfo.setFont(font);
        fedInfoField.setFont(font);
        solved.setFont(font);
        solvedField.setFont(font);
        solved.setFont(font);
        solvedField.setFont(font);


        frame.add(name);
        frame.add(NameField);
        frame.add(fedTime);
        frame.add(fedTimeField);
        frame.add(fedPId);
        frame.add(fedPIdField);
        frame.add(fedInfo);
        frame.add(fedInfoField);
        frame.add(solved);
        frame.add(solvedField);

        frame.add(solved);
        frame.add(solvedField);
        frame.add(btn);
        frame.add(btn2);

        name.setBounds(40, 50, 150, 40);
        NameField.setBounds(200, 50, 300, 40);
        fedTime.setBounds(40, 100, 150, 40);
        fedTimeField.setBounds(200, 100, 300, 40);
        fedPId.setBounds(40, 150, 150, 40);
        fedPIdField.setBounds(200, 150, 300, 40);
        fedInfo.setBounds(40, 200, 150, 40);
        fedInfoField.setBounds(200, 200, 300, 40);
        solved.setBounds(40, 250, 150, 40);
        solvedField.setBounds(200, 250, 300, 40);


        btn.setBounds(150, 310, 80, 30);
        btn2.setBounds(270, 310, 80, 30);

        btn.addActionListener(this);
        btn2.addActionListener(this);
    }


    @Override
    public void actionPerformed(ActionEvent e) {

        if (e.getSource() == btn) {
            if ("".equals(e.getActionCommand())) {
                JOptionPane.showMessageDialog(null, "请输入姓名！");

            } else {
                FeedbackInfoSqlSeverImpl dao = new FeedbackInfoSqlSeverImpl();
                FeedbackInfo feedbackInfo = new FeedbackInfo();
                feedbackInfo.setFeedback_name(NameField.getText());
                feedbackInfo.setFeedback_time(fedTimeField.getText());
                feedbackInfo.setFeedback_content(fedInfoField.getText());
                feedbackInfo.setProducts_id(Integer.valueOf(fedPIdField.getText()));
                feedbackInfo.setIsSolved(Boolean.parseBoolean(solvedField.getText()));

                int add = dao.add(feedbackInfo);
                System.out.println(add);
                if (add > 0) {
                    JOptionPane.showMessageDialog(null, "提交成功！");
                }
            }

        } else if ("清空".equals(e.getActionCommand())) {
            NameField.setText("");
            fedTimeField.setText("");
            fedPIdField.setText("");
            fedInfoField.setText("");
            solvedField.setText("");

        }


    }
}
